package com.viphuli.app.tool.common;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.offroader.utils.LogUtils;
import com.viphuli.app.tool.R;
import com.viphuli.app.tool.activity.MyToolBarActivity;
import com.viphuli.app.tool.fragment.AccountAddUserTypeFragment;
import com.viphuli.app.tool.fragment.AccountBindPhoneFragment;
import com.viphuli.app.tool.fragment.AccountFeedbackFragment;
import com.viphuli.app.tool.fragment.AccountFragment;
import com.viphuli.app.tool.fragment.AccountLoginFragment;
import com.viphuli.app.tool.fragment.AccountRemindFragment;
import com.viphuli.app.tool.fragment.ArrangeActionReplaceFragment;
import com.viphuli.app.tool.fragment.ArrangeRecordDetailArrangeFragment;
import com.viphuli.app.tool.fragment.ArrangeRecordDetailExchangeFragment;
import com.viphuli.app.tool.fragment.ArrangeRecordListFragment;
import com.viphuli.app.tool.fragment.ArrangeTypeEditFragment;
import com.viphuli.app.tool.fragment.ArrangeTypeListFragment;
import com.viphuli.app.tool.fragment.ArrangeViewFragment;
import com.viphuli.app.tool.fragment.CircleCreateFragment;
import com.viphuli.app.tool.fragment.CircleDepartmentAddFragment;
import com.viphuli.app.tool.fragment.CircleDepartmentListFragment;
import com.viphuli.app.tool.fragment.CircleHospitalAddFragment;
import com.viphuli.app.tool.fragment.CircleHospitalListFragment;
import com.viphuli.app.tool.fragment.CircleInfoFragment;
import com.viphuli.app.tool.fragment.CircleMemberFragment;
import com.viphuli.app.tool.fragment.CircleUserAddFragment;
import com.viphuli.app.tool.fragment.CircleUserAddManualFragment;
import com.viphuli.app.tool.fragment.CircleUserAddWechatFragment;
import com.viphuli.app.tool.fragment.HolidayFragment;
import com.viphuli.app.tool.fragment.HolidayLeaveAddFragment;
import com.viphuli.app.tool.fragment.HolidayLeaveSettingFragment;
import com.viphuli.app.tool.fragment.HolidayOverWorkAddFragment;
import com.viphuli.app.tool.fragment.HolidayTypeAddFragment;
import com.viphuli.app.tool.fragment.HomeFragment;
import com.viphuli.app.tool.fragment.SingleWebViewFragment;
import com.viphuli.app.tool.fragment.UpdateCircleDepartmentFragment;
import com.viphuli.app.tool.fragment.UpdateCircleHostFragment;
import com.viphuli.app.tool.fragment.UpdateCircleNameFragment;
import com.viphuli.app.tool.fragment.UpdateUserNameFragment;

/**
 * APP界面
 * @author li.li
 *
 */
public enum MyPageHelper {

	home(R.string.app_name, HomeFragment.class), //
	webView(R.string.str_single_webview_title, SingleWebViewFragment.class), //
	accountLogin(R.string.str_account_login_title, AccountLoginFragment.class), //
	accountBindPhone(R.string.str_account_bind_phone_title, AccountBindPhoneFragment.class), //
	account(R.string.str_account_title, AccountFragment.class), //
	accountRemind(R.string.str_account_remind_title, AccountRemindFragment.class), //
	accountFeedback(R.string.str_account_feedback_title, AccountFeedbackFragment.class), //
	circleInfo(R.string.str_circle_info_title, CircleInfoFragment.class), //
	circleCreate(R.string.str_account_create_circle_title, CircleCreateFragment.class), //
	accountAddUserType(R.string.str_account_add_user_type_title, AccountAddUserTypeFragment.class), //
	circleUserAdd(R.string.str_circle_user_add_title, CircleUserAddFragment.class), //
	circleUserAddManual(R.string.str_circle_user_add_manual_title, CircleUserAddManualFragment.class), //
	circleUserAddWechat(R.string.str_circle_user_add_wechat_title, CircleUserAddWechatFragment.class), //
	circleMember(R.string.str_circle_user_member_title, CircleMemberFragment.class), //
	circleHospitalList(R.string.str_circle_hospital_list_title, CircleHospitalListFragment.class), //
	circleDepartmentList(R.string.str_circle_department_list_title, CircleDepartmentListFragment.class), //
	circleHospitalAdd(R.string.str_circle_hospital_add_title, CircleHospitalAddFragment.class), //
	circleDepartmentAdd(R.string.str_circle_department_add_title, CircleDepartmentAddFragment.class), //
	arrangeTypeList(R.string.str_arrange_type_list_title, ArrangeTypeListFragment.class), //
	arrangeTypeEdit(R.string.str_arrange_type_edit_title, ArrangeTypeEditFragment.class), //
	arrangeRecordList(R.string.str_arrange_record_title, ArrangeRecordListFragment.class), //
	arrangeView(R.string.str_arrange_view_title, ArrangeViewFragment.class), //
	arrangeActionReplace(R.string.str_arrange_action_replace_title, ArrangeActionReplaceFragment.class), //
	arrangeRecordDetailArrange(R.string.str_arrange_details_arrange_title, ArrangeRecordDetailArrangeFragment.class), //
	arrangeRecordDetailExchange(R.string.str_arrange_details_exchange_title, ArrangeRecordDetailExchangeFragment.class), //
	updateCircleName(R.string.str_update_info_title, UpdateCircleNameFragment.class), //
	updateCircleHospital(R.string.str_update_info_title, UpdateCircleHostFragment.class), //
	updateCircleDeparment(R.string.str_update_info_title, UpdateCircleDepartmentFragment.class), //
	UpdateUserNameFragment(R.string.str_update_info_title, UpdateUserNameFragment.class), //
	holidayFragment(R.string.str_holiday_title, HolidayFragment.class), //
	holidayLeaveSettingFragment(R.string.str_holiday_leave_setting_title, HolidayLeaveSettingFragment.class), //
	holidayWorkRecordFragment(R.string.str_holiday_work_record_title, HolidayOverWorkAddFragment.class), //
	holidayLeaveRecordFragment(R.string.str_holiday_leave_record_title, HolidayLeaveAddFragment.class), //
	holidayLeaveTypeAddFragment(R.string.str_holiday_leave_type_add_title, HolidayTypeAddFragment.class), //
	;

	private int title;
	private Class<?> clz;

	private MyPageHelper(int title, Class<?> clz) {
		this.title = title;
		this.clz = clz;
	}

	public void showMyPage(Activity ctx) {
		Bundle args = new Bundle();
		showMyPage(ctx, args);
	}

	public void showMyPage(Activity ctx, int resultCode) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);
		Bundle args = new Bundle();

		showMyPage(ctx, args, intent, resultCode);

	}

	public void showMyPage(Activity ctx, Bundle args, int resultCode) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);

		showMyPage(ctx, args, intent, resultCode);

	}

	public void showMyPage(Activity ctx, Bundle args) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);

		showMyPage(ctx, args, intent, 0);

	}

	public void showMyPage(Activity ctx, Bundle args, String title) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);
		args.putString(MyToolBarActivity.BUNDLE_KEY_TITLE, title);

		showMyPage(ctx, args, intent, 0);

	}

	public void showMyPageClearTop(Activity ctx, Bundle args) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

		showMyPage(ctx, args, intent, 0);

	}

	private void showMyPage(Activity ctx, Bundle args, Intent intent, int resultCode) {

		if (args == null)
			args = new Bundle();

		//标题
		if (!args.containsKey(MyToolBarActivity.BUNDLE_KEY_TITLE))
			args.putString(MyToolBarActivity.BUNDLE_KEY_TITLE, ctx.getString(title));

		intent.putExtra(MyToolBarActivity.BUNDLE_KEY_ARGS, args);
		intent.putExtra(MyToolBarActivity.BUNDLE_KEY_NAME, name());

		if (resultCode != 0) {
			ctx.startActivityForResult(intent, resultCode);
		} else {
			ctx.startActivity(intent);
		}

	}

	public void showMyWebViewPage(Activity ctx, String url, String title) {
		LogUtils.info("接口请求|打开网页" + title + "|" + url);
		Bundle args = new Bundle();
		args.putString(SingleWebViewFragment.BROWSER_URL, url);
		args.putString(MyToolBarActivity.BUNDLE_KEY_TITLE, title);
		showMyPage(ctx, args);
	}

	public int getTitle() {
		return title;
	}

	public Class<?> getClz() {
		return clz;
	}

	public static MyPageHelper getPageByName(String name) {

		return MyPageHelper.valueOf(name);
	}
}
